package driver.ui.driver.Adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import driver.ui.R;
import driver.ui.driver.Beans.person;

public class ContactlistAdapter extends ArrayAdapter<person> {
	int resource;
    String response;
    Context context;
    //Initialize adapter
    public ContactlistAdapter(Context context, int resource, List<person> items) {
        super(context, resource, items);
        this.resource=resource;
 
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        LinearLayout setupView;
        //Get the current alert object
        person p = getItem(position);

 
        //Inflate the view
        if(convertView==null)
        {
            setupView = new LinearLayout(getContext());
            String inflater = Context.LAYOUT_INFLATER_SERVICE;
            LayoutInflater vi;
            vi = (LayoutInflater)getContext().getSystemService(inflater);
            vi.inflate(resource, setupView, true);
        }
        else
        {
            setupView = (LinearLayout) convertView;
        }
        //Get the text boxes from the listitem.xml file
        
        ImageView personImg =(ImageView)setupView.findViewById(R.id.contactimg);
        
        personImg.setImageResource(p.getImgsrc());
        TextView personName =(TextView)setupView.findViewById(R.id.contactname);
     
        Button personStatus =(Button)setupView.findViewById(R.id.contactstatus);
        personName.setText(p.getName());
     
        personStatus.setText(p.getStatus());
        if(p.getStatus().equals("Meeting")||p.getStatus().equals("Driving"))
        	personStatus.setBackgroundColor(Color.RED);
        else if(p.getStatus().equals("Available"))
        	personStatus.setBackgroundColor(Color.GREEN);
        else if(p.getStatus().equals("Offline"))
        	personStatus.setBackgroundColor(Color.GRAY);
        else if(p.getStatus().equals("Pending"))
        	personStatus.setBackgroundColor(Color.GRAY);
        	
        
 
        return setupView;
    }
 }
